package com.xique.park.controller.client.web.controller;

import com.xique.common.core.utils.StringUtils;
import com.xique.common.core.web.controller.BaseController;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.park.bean.request.client.ClientCashPassListRequest;
import com.xique.park.bean.request.comm.ParkOnEditPlateSaveRequest;
import com.xique.park.bean.vo.client.ClientCashPassListVo;
import com.xique.park.controller.client.web.bean.request.*;
import com.xique.park.controller.client.web.service.biz.service.IClientHomeBizService;
import com.xique.park.controller.client.web.service.biz.service.IClientRecordBizService;
import com.xique.park.controller.client.web.service.biz.service.IWxAppRecordBizService;
import com.xique.park.service.biz.service.IClientBizService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 停车记录相关方法controller
 */
@RestController
@RequestMapping("/app/record")
@Slf4j
public class WxAppParkRecordController extends BaseController {

    @Autowired
    private IClientHomeBizService clientHomeBizService;

    @Autowired
    private IClientBizService clientBizService;

    @Autowired
    private IWxAppRecordBizService wxAppRecordBizService;

    @Autowired
    private IClientRecordBizService clientRecordBizService;

    /**
     * 在场记录
     * @author shd
     * @date 2021/7/29 10:35
     * @param request
     * @return com.xique.common.core.web.domain.AjaxResult
     */
    @GetMapping("/parkOn/list")
    @ApiOperation("在场记录")
    public AjaxResult parkOnList(@Validated ClientParkOnListRequest request) {
        return wxAppRecordBizService.getParkOnList(request);
    }

    @GetMapping("/parkOn/getUrl")
    @ApiOperation("在场列表获取入场图片")
    public AjaxResult getParkOnUrl(@RequestParam("recordId") String recordId ) {
        return clientHomeBizService.getParkOnUrl(recordId);
    }

    @PostMapping("/parkOn/plate/edit")
    @ApiOperation("在场记录车牌修改")
    public AjaxResult editParkOnPlate(@Validated @RequestBody ParkOnEditPlateSaveRequest request) {
        boolean matches = StringUtils.isLegalPlate(request.getNewPlate());
        if (!matches){
            return  AjaxResult.error("车牌格式不正确!");
        }
        return  clientHomeBizService.editParkOnPlate(request);
    }

    @GetMapping("/multCar/list")
    @ApiOperation("多位多车记录")
    public AjaxResult multCarList(WebClientMultCarListRequest request) {
        return clientRecordBizService.getMultCarList(request);
    }

    @GetMapping("/inOut/list")
    @ApiOperation("出入场记录")
    public AjaxResult clientInOnList(WebClientInOutRecordRequest request) {
        return wxAppRecordBizService.getInOutList(request);
    }

    @PostMapping("record/cashPass")
    @ApiOperation("现金收费记录")
    public AjaxResult cashPassList(@Validated @RequestBody ClientCashPassListRequest request) {
        startPage();
        List<ClientCashPassListVo> listVos = clientBizService.clientCashPassList(request);
        return new AjaxResult(getDataTable(listVos));
    }
}
